package com.heima.article.job;
import com.heima.article.service.HotArticleService;
import com.heima.model.mess.app.AggBehaviorDTO;
import com.heima.model.mess.app.NewBehaviorDTO;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Component
@Slf4j
public class UpdateHotArticleJob {

    @Resource
    private HotArticleService hotArticleService;

    @XxlJob("updateHotArticleJob")
    public ReturnT updateHotArticleHandler(String params){
        log.info("热文章分值更新 调度任务开始执行....");
        List<NewBehaviorDTO> behaviorDTOList = hotArticleService.getBehaviorListFromRedis();
        if(CollectionUtils.isEmpty(behaviorDTOList)){
            log.info("项目太冷清了 最近59s中，没有访问文章....");
        }
        List<AggBehaviorDTO> aggBehaviorList = hotArticleService.getAggBehaviorList(behaviorDTOList);
        hotArticleService.batchUpdateApArticles(aggBehaviorList);
        log.info("热文章分值更新 调度任务完成....");
        return ReturnT.SUCCESS;
    }
}